package org.wisdom.ac.domain.user.entity;

import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.wisdom.data.jpa.entity.BaseEntity;

import javax.persistence.*;
import java.util.List;

/**
 * 系统用户
 *
 * @author 张智研
 * @date 2022/05/23 15:08
 **/
@SuppressWarnings("JpaDataSourceORMInspection")
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
@Slf4j
@NamedEntityGraph(name = "userWithRole",
    attributeNodes = {@NamedAttributeNode(value = "userRoles")})
public class AcUser extends BaseEntity {

    /** 用户账号 */
    @Column(nullable = false, updatable = false, unique = true)
    @Order(1)
    private String userName;

    /** 用户密码 */
    @Column(nullable = false, updatable = false)
    @Order(2)
    private String password;

    /** 用户昵称 */
    @Order(3)
    private String aliasName;

    /** 员工id */
    @Order(4)
    private String staffId;

    @Column(nullable = false)
    @Order(5)
    private Boolean enabled;

    /** 用户拥有的角色 */
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "userId")
    @Order(5)
    private List<AcUserRole> userRoles;
}
